package GraphProperties;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Serializable;

import Global.ConstantVariable;
import Global.DirectoryStructureAndSettingsClass;
import Global.GlobalClass;
import SyntheticData.syntheticDataGeneratorClass;
import SyntheticData.syntheticDataGeneratorClass.TogetherFilesHolderClass;
import Utility.WorkerUtilityClass;

public class DegreeDistributionRelatedPropsClass extends GenericGraphPropertyClass implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 9175136201572985926L;
	double[] degreeListOfNodes;	
	double[] degreeLevels;
	double[] originalDegreeLevels;
	double[] degreeFrequencyForTheLevels;	
	double averageDegree;
	
	DegreeDistributionRelatedPropsClass(PropertiesOfGraphClass propertiesIBelongTo)
	{
		super(propertiesIBelongTo);
		averageDegree = 0;
	}
	
	public void setDegreeDistributionRelatedParameters(double[] degreeListOfNodes, double[] degreeLevels, double[] degreeFrequencyForTheLevels, double averageDegree)	
	{
		this.degreeListOfNodes = degreeListOfNodes;
		originalDegreeLevels = degreeLevels;
		this.degreeLevels = WorkerUtilityClass.convertToSomeScale(degreeLevels);
		this.degreeFrequencyForTheLevels = degreeFrequencyForTheLevels;
		this.averageDegree = averageDegree;
		
		degreeDistributionCalculationIsCompleted();		
	}
	
	public double[] getDegreeListOfNodes()
	{
		return degreeListOfNodes;
	}
	
	public double getAverageDegreeOfNodes()
	{
		return averageDegree;
	}
	
	public double[] getDegreeLevels()
	{
		return degreeLevels;
	}

	public double[] getOrginalDegreeLevels()
	{
		return originalDegreeLevels;
	}
	
	void degreeDistributionCalculationIsCompleted()
	{
		String datasetName =DirectoryStructureAndSettingsClass.getDatasetName();
		try {
			
			/**************************PURE DEGREE LIST*********************************/
			
			outForPureRawFile = createRawPureDegreeResultsFile(datasetName);
			Utility.FileUtilityClass.writeArrayToFile(outForPureRawFile, degreeListOfNodes, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForDegreesOfNodes, "Degrees of Nodes for " + datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType);
			outForPureRawFile.close();
			
			/**************************DEGREE DISTRIBUTION LIST*********************************/
		
			outForRawFile = createRawDegreeDistributionResultsFile(datasetName);
			Utility.FileUtilityClass.writeTwoArraysToFile(outForRawFile, degreeLevels, degreeFrequencyForTheLevels, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForDegreesDistributionLevelsOfNodes, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForDegreesDistributionFrequencyLevelsOfNodes, "Degrees of Distribution Of The Graph for " + datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType);
			outForRawFile.close();
			
			/************************** DD LINEAR BAR PLOTS*********************************/		
			
			String drawingSetting = null;
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
				drawingSetting = ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_FIGURE_FOR_LINK_GRAPH;
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
				drawingSetting = ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_FIGURE_FOR_CONTENT_GRAPH;
			
			outForMatlabCodeFile = createMatlabCodeDegreeDistributionResultsFile(datasetName);
			createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, false, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.DONT_CARE, drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);			
			outForMatlabCodeFile.close();
			
			outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE);
			prepareTexFileForTheCreatedMatlabFigure();			
			outForTexForMatlabFigureFile.close();
			
			copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.DD_LINEAR_SCALE_MATLAB_FIGURES_TEX_IN_ONE_FILENAME, false);
			
			/************************** DD LOG-LOG PLOTS*********************************/			
			
			outForMatlabCodeFileLogScale = createMatlabCodeDegreeDistributionLogScaleResultsFile(datasetName);
			createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFileLogScale, ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE, false, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.DONT_CARE, drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);			
			outForMatlabCodeFileLogScale.close();
			
			outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE);
			prepareTexFileForTheCreatedMatlabFigure();			
			outForTexForMatlabFigureFile.close();
			
			copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.DD_LOG_SCALE_MATLAB_FIGURES_TEX_IN_ONE_FILENAME, false);			
			
			/************************** DD SEMI-LOG PLOTS*********************************/
			
			outForMatlabCodeFileLogScale = createMatlabCodeDegreeDistributionSemiLogYScaleResultsFile(datasetName);
			createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFileLogScale, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE, false, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.DONT_CARE, drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);			
			outForMatlabCodeFileLogScale.close();
			
			outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE);
			prepareTexFileForTheCreatedMatlabFigure();			
			outForTexForMatlabFigureFile.close();
			
			copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.DD_SEMI_LOG_Y_SCALE_MATLAB_FIGURES_TEX_IN_ONE_FILENAME, false);
			
			/************************** DD LINEAR TOGETHER PLOTS FOR SYNTHETIC*********************************/			
			
			//TODO AS EKLEME YAPIYOR..AYNI PARAMETRELI DATASET PLOTLARINI AYNI GRAFTA YAPMA!!!
			if(GlobalClass.RunningValues.executionFor==ConstantVariable.DataSet_Constants.SYNTETIC_DATASET)
			{				
				TogetherFilesHolderClass currentTogetherFileHolder;
				currentTogetherFileHolder = syntheticDataGeneratorClass.getOutForMatlabCodeLinearDDPDFResultsTogetherFile();
				String nameBackup = new String(matlabFileName);			
				matlabFileName = currentTogetherFileHolder.matlabFileName;
				outForMatlabCodeFile = currentTogetherFileHolder.out;				 
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, true, syntheticDataGeneratorClass.getGraphOrderForTogetherGraphicResults(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE, false), drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, false);
				matlabFileName = nameBackup;
			}
								
			/**************************DD LINEAR BAR COMBO PLOTS *********************************/
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
			{
				outForMatlabCodeFile = createMatlabCodeDegreeDistributionComboResultsFile(datasetName, false);
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_COMBO_FIGURE_FOR_LINK_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);			
			}
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForMatlabCodeFile = createMatlabCodeDegreeDistributionComboResultsFile(datasetName, true);
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.LAST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_COMBO_FIGURE_FOR_CONTENT_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);
			}
				
			outForMatlabCodeFile.close();

			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.LINEAR_SCALE);
				prepareTexFileForTheCreatedMatlabFigure();			
				outForTexForMatlabFigureFile.close();
				
				copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.DD_LINEAR_SCALE_MATLAB_FIGURES_TEX_COMBO_IN_ONE_FILENAME, true);
			}		
			
			/************************** DD LOG-LOG BAR COMBO PLOTS*********************************/
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
			{
				outForMatlabCodeFileLogScale = createMatlabCodeDegreeDistributionLogScaleComboResultsFile(datasetName, false);
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFileLogScale, ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_COMBO_FIGURE_FOR_LINK_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);				
			}
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForMatlabCodeFileLogScale = createMatlabCodeDegreeDistributionLogScaleComboResultsFile(datasetName, true);
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFileLogScale, ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.LAST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_COMBO_FIGURE_FOR_CONTENT_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);
			}
			outForMatlabCodeFileLogScale.close();

			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE);
				prepareTexFileForTheCreatedMatlabFigure();			
				outForTexForMatlabFigureFile.close();
				
				copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.DD_LOG_SCALE_MATLAB_FIGURES_TEX_COMBO_IN_ONE_FILENAME, true);
			}
			
			/************************** DD LOG-LOG TOGETHER PLOTS FOR SYNTHETIC*********************************/
			
			//TODO AS EKLEME YAPIYOR..AYNI PARAMETRELI DATASET PLOTLARINI AYNI GRAFTA YAPMA!!!
			if(GlobalClass.RunningValues.executionFor==ConstantVariable.DataSet_Constants.SYNTETIC_DATASET)
			{				
				TogetherFilesHolderClass currentTogetherFileHolder;
				currentTogetherFileHolder = syntheticDataGeneratorClass.getOutForMatlabCodeLogLogDDPDFResultsTogetherFile();
				String nameBackup = new String(matlabFileName);			
				matlabFileName = currentTogetherFileHolder.matlabFileName;
				outForMatlabCodeFile = currentTogetherFileHolder.out;				 
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE, true, syntheticDataGeneratorClass.getGraphOrderForTogetherGraphicResults(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE, false), drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, false);
				matlabFileName = nameBackup;
			}
			
			/************************** DD SEMI-LOG BAR COMBO PLOTS*********************************/
			
			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE)
			{
				outForMatlabCodeFileLogScale = createMatlabCodeDegreeDistributionSemiLogScaleYComboResultsFile(datasetName, false);
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFileLogScale, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.FIRST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_COMBO_FIGURE_FOR_LINK_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);				
			}
			else if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForMatlabCodeFileLogScale = createMatlabCodeDegreeDistributionSemiLogScaleYComboResultsFile(datasetName, true);
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFileLogScale, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE, true, ConstantVariable.Matlab_ConstantVariables.GraphOrderType.LAST_GRAPH, ConstantVariable.Matlab_ConstantVariables.DrawingSettings.DegreeRelatedDrawingSettings.DRAWING_SETTING_FOR_DEGREE_DISTRIBUTION_COMBO_FIGURE_FOR_CONTENT_GRAPH, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, true);
			}
			outForMatlabCodeFileLogScale.close();

			if(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE_FOR_CONTENT_GRAPH)
			{
				outForTexForMatlabFigureFile = createTexFileForTheGeneratedMatlabFigure(propertiesIBelongTo.edgeType, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE);
				prepareTexFileForTheCreatedMatlabFigure();			
				outForTexForMatlabFigureFile.close();
				
				copyTexForTheFigureTo(ConstantVariable.DefaultFileNamesConstants.DefaultAllInOneResultsFiles.DD_SEMI_LOG_Y_SCALE_MATLAB_FIGURES_TEX_COMBO_IN_ONE_FILENAME, true);
			}
			
			/************************** DD SEMI-LOG TOGETHER PLOTS FOR SYNTHETIC*********************************/
			
			//TODO AS EKLEME YAPIYOR..AYNI PARAMETRELI DATASET PLOTLARINI AYNI GRAFTA YAPMA!!!
			if(GlobalClass.RunningValues.executionFor==ConstantVariable.DataSet_Constants.SYNTETIC_DATASET)
			{
				TogetherFilesHolderClass currentTogetherFileHolder;
				currentTogetherFileHolder = syntheticDataGeneratorClass.getOutForMatlabCodeSemiLogYDDPDFResultsTogetherFile();
				String nameBackup = new String(matlabFileName);			
				matlabFileName = currentTogetherFileHolder.matlabFileName;
				outForMatlabCodeFile = currentTogetherFileHolder.out;				 
				createDegreeDistributionPlotCodeForMatlab(outForMatlabCodeFile, ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE, true, syntheticDataGeneratorClass.getGraphOrderForTogetherGraphicResults(propertiesIBelongTo.edgeType==ConstantVariable.Common_ConstantVariables.DEFAULT_EDGE_TYPE, false), drawingSetting, ConstantVariable.Matlab_ConstantVariables.DistributionType.PDF_TYPE, false);
				matlabFileName = nameBackup;
			}
			
			//Utility.FileUtilityClass.writeArrayToFile(outForRawFile, degreeListOfNodes, ConstantVariable.Format_ConstantVariables.numberFormatToBeUsedForDegreesOfNodes, "Degrees of Nodes for " + datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType);
			//outForRawFile.close();

		} catch (IOException e) {			
			e.printStackTrace();
		}		
	}	
	
    public BufferedWriter createRawPureDegreeResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.RAW_DATA_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"DegreesOfNodes.txt"; 
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    /**********************************************/

	
	
    public BufferedWriter createRawDegreeDistributionResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.RAW_DATA_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"DegreeDistribution.txt"; 
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    /**********************************************/

    public BufferedWriter createMatlabCodeDegreeDistributionResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME;    				
    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"DegreeDistribution";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public BufferedWriter createMatlabCodeDegreeDistributionSemiLogYScaleResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME;    				
    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"SemiLogYScaleDD";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public BufferedWriter createMatlabCodeDegreeDistributionLogScaleResultsFile(String datasetName)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME;    				
    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+propertiesIBelongTo.edgeType+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"LogScaleDegreeDistribution";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    /**********************************************/

    public BufferedWriter createMatlabCodeDegreeDistributionComboResultsFile(String datasetName, boolean appendMode)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME;    				
    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"DDCombo";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile, appendMode);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public BufferedWriter createMatlabCodeDegreeDistributionLogScaleComboResultsFile(String datasetName, boolean appendMode)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME;    				
    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"LogScaleDDCombo";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	System.out.println("fullPathOfTheMatlabFile:"+fullPathOfTheMatlabFile);
    	System.out.println("fileName:"+fileName);
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile, appendMode);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    public BufferedWriter createMatlabCodeDegreeDistributionSemiLogScaleYComboResultsFile(String datasetName, boolean appendMode)
    {
    	String path= DirectoryStructureAndSettingsClass.getFullPathOfTheRootDirectoryNameForTheCurrentDataset()
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDatasetDirectory.GRAPH_PROPERTIES_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGraphPropertiesDirectory.DEGREE_RELATED_DATA_FOLDER_NAME
    				+ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderDegreeRelatedDirectory.DEGREE_DISTRIBUTION_DATA_FOLDER_NAME;    				
    	
    	fullPathOfParentDirectoryOfMatlabCode = path;    	
    	path = path + ConstantVariable.DefaultDirectoryNamesConstants.DirectoriesUnderGenericGraphPropertyDirectory.MATLAB_CODE_FOLDER_NAME;
    	
    	String fileName = datasetName+ConstantVariable.Format_ConstantVariables.DASH_CHAR+"SemiLogScaleDDCombo";
    	matlabFileName = fileName;
    	fullPathOfTheMatlabFile = path;
    	
    	fileName += ".m";
    	
    	System.out.println("fullPathOfTheMatlabFile:"+fullPathOfTheMatlabFile);
    	System.out.println("fileName:"+fileName);
    	
    	try {
    		
    		File descFile=DirectoryStructureAndSettingsClass.createFile(path, fileName);
    		FileWriter fstream;
    		fstream = new FileWriter(descFile, appendMode);
    		BufferedWriter out = new BufferedWriter(fstream);
    		return out;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
    }
    
    void createDegreeDistributionPlotCodeForMatlab(BufferedWriter outForMatlabCodeFile, int type, boolean isForCombo, int order, String drawingSettings, int distributionPlotType, boolean generateFigure)
    {
    	double[] degreeLevelsLocal = degreeLevels;
    	
    	//if(type == ConstantVariable.Matlab_ConstantVariables.ScaleType.LOGLOG_SCALE || type == ConstantVariable.Matlab_ConstantVariables.ScaleType.SEMI_LOG_Y_SCALE)
    		degreeLevelsLocal = WorkerUtilityClass.invertConvertionOfSomeScale(degreeLevels);
    		
    	createPlotCodeForMatlab(outForMatlabCodeFile, type, isForCombo, order, degreeLevelsLocal, degreeFrequencyForTheLevels, null, "Degree Distribution", "Degree (D)", "P(Degree)", drawingSettings, distributionPlotType, generateFigure);		
    }
}
